from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic import View, TemplateView, ListView
from article.models import Article


class Index(View):
    def get(self, request):
        return HttpResponse("hello")

    def http_method_not_allowed(self, request):
        return HttpResponse("meizhaodao")

    def dispatch(self, request, *args, **kwargs):
        return HttpResponse("必须经过我")


class About(TemplateView):
    template_name = 'add.html'

    def get_context_data(self):
        context = {}
        return context


class ArticleH(ListView):
    model = Article
    template_name = "index.html"
    context_object_name = "articles"
    paginate_by = 2
    ordering = 'id'
    page_kwarg = 'page'

    def get_context_data(self, *, object_list=None, **kwargs):
        content = super(ArticleH, self).get_context_data()
        paginator = content.get('paginator')
        page = content.get('page_obj')
        print(content)
        return content

    # def get_queryset(self):
    #     return Article.object.filter()